package main

import (
	"fmt"
	"os"
)

/*
	func Open(name string) (file *File, err error)
	func OpenFile(name string, flag int, perm FileMode) (file *File, err error)
	flag: 指定打开文件方式：只读、只写...
	perm：只读打开文件模式&权限：

	func (f *File) Close() error
*/
func main() {
	// open
	// f, err := os.Open("../interface/test1.go")
	f, err := os.Open("../interface/tes1.go") // file not exists
	if err != nil {
		fmt.Println(err) // open /usr/local/goproject/src/go_code/project1/interface/tes1.go: no such file or directory
	}
	defer f.Close()
	fmt.Printf("file val is %v\n", f) // file val is &{0xc000058180}

	// test OpenFile
	f1, err1 := os.OpenFile("./test.txt", os.O_CREATE|os.O_RDWR|os.O_APPEND, os.ModeAppend|os.ModePerm)
	if err1 != nil {
		fmt.Println(err1)
	}
	fmt.Println("f1 val is ", f1)
	defer f1.Close()

}
